#pragma once
#include <iostream>
#include <vector>
#include <sys/types.h>
#include <unistd.h>

#define COMMAND_LOG 0
#define COMMAND_MYSQL 1
#define COMMAND_REQUEST 2

typedef void (*fun_t)();

void PrintLog()
{
    std::cout << "进程 [" << getpid() << "] 正在执行：打印日志任务..." << std::endl;
}

void InsertMySQL()
{
    std::cout << "进程 [" << getpid() << "]正在执行：数据库相关任务..." << std::endl;
}

void NetRequest()
{
    std::cout << "进程 [" << getpid() << "]正在执行：网络请求相关任务..." << std::endl;
}

class Task
{
public:
    Task()
    {
        funcs.push_back(PrintLog);
        funcs.push_back(InsertMySQL);
        funcs.push_back(NetRequest);
    }
    /*
        接收的command是4字节的整形，范围>=0
    */
    void Execute(int command)
    {
        if (command >= 0 && command < funcs.size())
            funcs[command]();
    }
    std::vector<fun_t> funcs;
};